package com.liyiqing.secondhandmall.memberservice.controller;

import java.util.Arrays;
import java.util.Map;

import com.liyiqing.commonservice.validator.methodgroup.AddGroup;
import com.liyiqing.commonservice.validator.methodgroup.UpdateGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liyiqing.secondhandmall.memberservice.entity.MemberUserReceiveAddressEntity;
import com.liyiqing.secondhandmall.memberservice.service.MemberUserReceiveAddressService;
import com.liyiqing.commonservice.utils.PageUtils;
import com.liyiqing.commonservice.utils.R;



/**
 * 收货地址
 *
 * @author LiYiQing
 * @email 1570865668@qq.com
 * @date 2022-02-18 22:47:22
 */
@RestController
@RequestMapping("memberService/memberUserReceiveAddress")
public class MemberUserReceiveAddressController {
    @Autowired
    private MemberUserReceiveAddressService memberUserReceiveAddressService;

    /**
     * 查找所有收货地址
     */
    @RequestMapping("/selectAllReceiveAddress")
    public R selectAllReceiveAddress(){
         return memberUserReceiveAddressService.selectAllReceiveAddress();
    }


    /**
     * 根据主键id查找信息
     */
    @RequestMapping("/selectReceiveAddressById/{id}")
    public R selectReceiveAddressById(@PathVariable("id") Long id){
        return memberUserReceiveAddressService.selectReceiveAddressById(id);
    }


    /**
     * 根据主键id查找信息
     */
    @RequestMapping("/selectAddressByMemberId/{memberId}")
    public R selectAddressByMemberId(@PathVariable("memberId") Long memberId){
        return memberUserReceiveAddressService.selectAddressByMemberId(memberId);
    }



    /**
     * 新增收货地址
     */
    @RequestMapping("/insertReceiveAddress")
    public R insertReceiveAddress(@Validated({AddGroup.class}) @RequestBody MemberUserReceiveAddressEntity receiveAddress){
        if (receiveAddress.getStatus()==null){
            receiveAddress.setStatus(1);
        }
        memberUserReceiveAddressService.save(receiveAddress);
        return R.ok().put("data",receiveAddress);
    }

    /**
     * 根据id修改收货地址
     */
    @RequestMapping("/updateReceiveAddress")
    public R update(@Validated({UpdateGroup.class}) @RequestBody MemberUserReceiveAddressEntity receiveAddress){
		memberUserReceiveAddressService.updateById(receiveAddress);
        return R.ok().put("data",receiveAddress);
    }


    /**
     * 根据主键id删除收货地址
     */
    @RequestMapping("/deleteReceiveAddressById/{id}")
    public R deleteReceiveAddressById(@PathVariable Long id){
        memberUserReceiveAddressService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id批量删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberUserReceiveAddressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
